<template>
  <el-row class="">
    <el-col :span="2"></el-col>
    <el-col :span="16">
      <el-table :data="beanBillList" :default-sort="{ prop: 'createTime', order: 'descending' }" stripe
                style="width: 100%;margin-top: 40px">
        <el-table-column prop="id" label="账单ID"/>
        <el-table-column prop="balanceChangeValue" label="余额变动值"/>
        <el-table-column prop="balance" label="变动后余额"/>
        <el-table-column prop="usageModeName" label="使用方式" />
        <el-table-column prop="createTime" label="创建时间" />
      </el-table>
      <div class="demo-pagination-block" style="margin-top: 20px">
        <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :page-sizes="[5, 10, 20, 50, 100]"
            :background="true"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
      </div>
    </el-col>
    <el-col :span="4"></el-col>
  </el-row>


</template>

<script setup>
import {onMounted, ref} from "vue";
import {ElMessage} from 'element-plus'
import {useUserinfo} from "@/components/hooks/useUserinfo.js";
import {GetBeanBillByUserId} from '@/api/member/user.js'
import {useRouter} from "vue-router";

const router = useRouter()
const {userinfo} = useUserinfo()


// 分页
const currentPage = ref(1)
const pageSize = ref(5)
const totalCount = ref(0)
const handleSizeChange = (size) => {
  getBeanBillByUserId()
}
const handleCurrentChange = (page) => {
  getBeanBillByUserId()
}


// 用户仙豆账单信息
const beanBillList = ref([]);
const getBeanBillByUserId = async () => {
  try {
    const params = {
      userId: userinfo.value.id,
      page: currentPage.value,
      size: pageSize.value,
    }
    const {code, data, msg} = await GetBeanBillByUserId(params);
    if (code === 200) {
      beanBillList.value = data.beanBillList;
      totalCount.value = data.totalCount;
    } else {
      ElMessage.error(msg)
    }
  } catch (error) {
    ElMessage.error(error)
  }
}


onMounted(() => {
  getBeanBillByUserId()
})
</script>

<style scoped>

</style>